#pragma strict
//////////////////////////////////////////////////////
///场景中油桶爆炸,效果控制器
//////////////////////////////////////////////////////
var groundEffect:Transform; //爆炸时,地面上的粒子
var fireEffect:Transform; //爆炸是,火焰粒子.
var isDestoryWhenPlayFinish:boolean = true; //爆炸动画播放完毕是否销毁?
var expClip:AudioClip; //爆炸音效.
/** 初始时 需要隐藏的网格 */
var rendersNotShowWhenStart:Renderer[];

private var curAnim:Animation;
private var tr:Transform;

function Start () {
	curAnim = animation;
	tr = transform;
	
	Show(false);
}

var isTest:boolean;
function Update(){
	if(isTest){
		isTest = false;
		OnDead();
	}
}

function Show(isShow:boolean){
	if(rendersNotShowWhenStart){
		for(var r:Renderer in rendersNotShowWhenStart){
			r.enabled = isShow;
		}
	}
}

function StartExp(){
	Show(true);
	curAnim.Play(curAnim.clip.name);
	
	if(groundEffect){
		Instantiate(groundEffect,tr.position,Quaternion.identity);
	}
	if(fireEffect){
		Instantiate(fireEffect,tr.position,Quaternion.identity);
	}
	
	if(expClip){
		if(! audio)
			gameObject.AddComponent.<AudioSource>();
		audio.PlayOneShot(expClip);
	}
	
	yield WaitForSeconds(curAnim.clip.length);
	if(isDestoryWhenPlayFinish)
		Destroy(gameObject);
}
/* HealthController的死亡通知 */
function OnDead(){
	Destroy(rigidbody);
	Destroy(collider);
	StartExp();
}